import { lastValueFrom } from "rxjs";
import { Injectable } from "@nestjs/common";

import {
  PutRes,
  RestDto,
  ENUM_APP,
  PaymentWeChatMp,
  putPaymentWxmpRpcDto,
  getPaymentWxmpRpcDto,
  PaymentWxmpRpcPutPath,
  PaymentWxmpRpcGetPath,
  PaymentWxmpRpcInterface,
} from "qqlx-core";
import {} from "qqlx-cdk";

import { BusRpc } from "./app.droplet-bus";
import { RpcWaiting } from "./rpc.response";
import { RpcConnection } from "./com.connection";

@Injectable()
export class PaymentWxmpRpc extends RpcConnection implements PaymentWxmpRpcInterface<RestDto> {
  constructor(readonly BusRpc: BusRpc) {
    super(BusRpc, ENUM_APP.STREAM_PAY);
  }

  @RpcWaiting(PaymentWxmpRpcGetPath)
  async get(dto: RestDto & getPaymentWxmpRpcDto) {
    const ob = this.CLIENT.send(PaymentWxmpRpcGetPath, dto);
    return lastValueFrom<{ entities: PaymentWeChatMp[] }>(ob);
  }

  @RpcWaiting(PaymentWxmpRpcPutPath)
  async put(dto: RestDto & putPaymentWxmpRpcDto) {
    const ob = this.CLIENT.send(PaymentWxmpRpcPutPath, dto);
    return lastValueFrom<PutRes<PaymentWeChatMp>>(ob);
  }
}
